package controller;

import org.junit.Test;
import pojo.Admin;
import service.AdminService;
import service.AdminServiceImpl;
import service.ClassroomService;
import service.ClassroomServiceImpl;

import java.util.ArrayList;
import java.util.Scanner;

public class AdminController {
    private AdminService service = new AdminServiceImpl();
    /*
        查询所有管理员信息
     */
    @Test
    public void findAll() {
        ArrayList<Admin> list = service.findAll();
        for(Admin admin : list) {
            System.out.println(admin);
        }
    }
/*

        登录操作
   */
    @Test
    public void login() {
        Scanner scanner = new Scanner(System.in);
        System.out.println("输入账户：");
        Integer account = 18001;
        System.out.println("输入密码：");
        String password = "123456";
        if (service.checkAdminPassword(account, password)) {
            if (service.isSuperAdmin(account)) {
                System.out.println("欢迎超级管理员");
            } else System.out.println("欢迎普通管理员");
        } else {
            System.out.println("账户或密码错误");
        }
    }

/*

        添加管理员信息
     */
    @Test
    public void insert() {
        Admin admin = new Admin(18003,"12321","wangwu","24444444444",false);
        int result = service.insert(admin);

        if(result!=0) {
            System.out.println("添加成功");
        }else {
            System.out.println("添加失败");
        }
    }

    /*
        修改管理员信息
     */
    @Test
    public void update() {
        Admin admin = service.findByAdminAcount(18003);
        admin.setSuper(true);

        int result = service.update(admin);

        if(result != 0) {
            System.out.println("修改成功");
        }else {
            System.out.println("修改失败");
        }
    }

    @Test
    public void updatePermission(){
        System.out.println(service.updatePermissions(18003));
    }
    @Test
    public void delete() {
        int result = service.delete(18003);

        if(result != 0) {
            System.out.println("删除成功");
        }else {
            System.out.println("删除失败");
        }
    }
}
